
void RCINIT(){
  
RXCHmin[1] = -9;
RXCHmin[2] = 0;
RXCHmax[1] = 466;
RXCHmax[2] = 514;
pinMode(A0,INPUT);
pinMode(A1,INPUT);
pinMode(A2,INPUT);
pinMode(A3,INPUT);
  //Assign PPM input pins. The receiver output pins are conected as be0 to non-PWM Digital connectors:
  RXCH[1] = A0;  //Throttle
  RXCH[2] = A1;  //Aile / Yaw
  RXCH[3] = A2;  //Elev. / Pitch
  RXCH[4] = A3;  //Rudd. / Roll
//  RXCH[5] = A4;  //Gear
//  RXCH[6] = A5;  //Aux / Flt Mode
 
}
boolean RConline = false;
void RC_READ(){
  
   // Read RX values
  for (int i = 1; i < 7; i++){						    //for each of the 6 channels:
  RXSG[i] = pulseIn(RXCH[i], 254, 20000);				    //read the receiver signal
  if (RXSG[i] == 0) {
  RConline = true;
  RXSG[i] = RXOK[i];
} else {
  RConline = false;
  //RXOK[i] = RXSG[i];
}    //if the signal is good then use it, else use the previous signal
//  PWMSG[i] = map(RXSG[i], 1000, 2000, 0, 511);				//substitute the 254 values to a value between 0 and 511
  PWMSG[i] = RXSG[i];				//substitute the 254 values to a value between 0 and 511
  constrain (PWMSG[i], 1000, 2000);	

  RXCHval[i] = PWMSG[i];
  
  if (PWMSG[i] < RXCHmin[i]){
    RXCHmin[i] = PWMSG[i];
  }
  if (PWMSG[i] > RXCHmax[i]){
    RXCHmax[i] = PWMSG[i];
  }
  delay(5);
}

}

